
#include <stdio.h>
#include <stdlib.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <sdl/sdl.h>
#include "guacimage.h"

// Parameters: FILE* pointer
// Returns: light userdata to SDL_Surface
int raw_loadbmp(lua_State* L)
{
    FILE* fp = *(FILE**)lua_touserdata(L,1);
    SDL_RWops *rw = SDL_RWFromFP(fp, 0);
    SDL_Surface* surf = SDL_LoadBMP_RW(rw, 0);
    if (!surf)
        return luaL_error(L, SDL_GetError());

    GuacImage* img = (GuacImage*)lua_newuserdata(L, sizeof(GuacImage));
    img->surf = surf;
    img->prect = NULL;
    img->flags = 0;
    img->handle_x = img->handle_y = 0;

    return 1;
}
